package com.yuncommunity.runcircle;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.oldfeel.base.BasePagerAdapter;
import com.yuncommunity.runcircle.base.MyActivity;
import com.yuncommunity.runcircle.fragment.AnalysisFragment;
import com.yuncommunity.runcircle.fragment.HistoryFragment;
import com.yuncommunity.runcircle.view.NoScrollViewPager;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by oldfeel on 11/22/15.
 */
public class RunDetail extends MyActivity {
    @Bind(R.id.analysis)
    RadioButton analysis;
    @Bind(R.id.history)
    RadioButton history;
    @Bind(R.id.nav)
    RadioGroup nav;
    @Bind(R.id.view_pager)
    NoScrollViewPager viewPager;
    BasePagerAdapter pagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.run_detail);
        ButterKnife.bind(this);
        pagerAdapter = new BasePagerAdapter(getSupportFragmentManager());
        pagerAdapter.add(new AnalysisFragment());
        pagerAdapter.add(new HistoryFragment());
        viewPager.setAdapter(pagerAdapter);
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                nav.check(position == 0 ? R.id.analysis : R.id.history);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        viewPager.setPagingEnabled(false);
        nav.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                viewPager.setCurrentItem(checkedId == R.id.analysis ? 0 : 1);
            }
        });
    }

    @OnClick(R.id.back)
    public void back() {
        onBackPressed();
    }
}
